local skill = fk.CreateSkill {
  name = "ksp__chenzhu_peach_skill",
}

Fk:loadTranslationTable{
  ["#ksp__chenzhu_peach_skill"] = "令你或一名拥有【臣主】的角色回复1点体力",
  ["#ksp__chenzhu_peach_skill-ask"] = "令 %dest 回复1点体力",
}

skill:addEffect("cardskill", {
  prompt = function (self, player, selected_cards, selected_targets, extra_data)
    if player.kingdom == "shu" and player.phase == Player.Play then
      if #selected_targets > 0 then
        return "#ksp__chenzhu_peach_skill-ask::"..selected_targets[1].id
      end
      return "#ksp__chenzhu_peach_skill"
    else
      return "#peach_skill"
    end
  end,
  mod_target_filter = function(self, player, to_select)
    return to_select:isWounded()
  end,
  fix_targets = function (self, player, card, extra_data) --危险
    if not player:isWounded() and card.name == "peach" and player.kingdom == "shu" and player.phase == Player.Play then
      local tos = table.filter(Fk:currentRoom().alive_players, function(p)
        return not player:isProhibited(p, card) and p:hasSkill("ksp__chenzhu") and p:isWounded()
      end)
      return tos
    end
    return {player}
  end,
  can_use = function (self, player, card, extra_data)
    if card.name == "peach" and player.kingdom == "shu" and player.phase == Player.Play then
      return Util.CanUseToSelf(self, player, card, extra_data) or table.find(Fk:currentRoom().alive_players, function(p)
        return not player:isProhibited(p, card) and p:hasSkill("ksp__chenzhu") and p:isWounded()
      end) ~= nil
    end
    return Util.CanUseToSelf(self, player, card, extra_data)
  end,
  max_target_num = 1,
  target_filter = function (self, player, to_select, selected, selected_cards, card, extra_data)
    if card.name == "peach" and player.kingdom == "shu" and player.phase == Player.Play then
      return to_select:hasSkill("ksp__chenzhu") and to_select:isWounded() and to_select ~= player
    end
  end,
  feasible = function (self, player, selected, selected_cards)
    if player.kingdom == "shu" and player.phase == Player.Play and not player:isWounded() then
      return #selected == 1
    end
    return true
  end,
  on_effect = function(self, room, effect)
    if effect.to:isWounded() and not effect.to.dead then
      room:recover{
        who = effect.to,
        num = 1,
        card = effect.card,
        recoverBy = effect.from,
        skillName = "peach_skill",
      }
    end
  end,
})


return skill
